package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation{
    public void work(BookList bookList){
        Scanner sc=new Scanner(System.in);
        System.out.println("删除图书");
        System.out.println("输入要删除的图书名:");
        String name=sc.nextLine();
        int size= bookList.getUsedsize();
        int i=0;
        for(i=0;i<size;i++){
            Book book=bookList.getBook(i);
            if(book.getName().equals(name)){
               for(;i<size-1;i++){
               book=bookList.getBook(i+1);
               bookList.setBook(i,book);
               }
               bookList.setUsedsize(bookList.getUsedsize()-1);
                System.out.println("删除图书成功");
               return;
            }
            }
            if(i>=size){
                System.out.println("没有这本书!");
                return;
            }
    }
}
